package com.yunche.yunchebusiness.mvp.presenter

import com.yunche.yunchebusiness.base.mvp.BasePresenter
import com.yunche.yunchebusiness.mvp.contract.UserContract
import com.yunche.yunchebusiness.mvp.model.UserModel
import com.yunche.yunchebusiness.network.exception.ErrorStatus
import com.yunche.yunchebusiness.network.exception.ExceptionHandle

/**
 * Create by Crcker on 2018/12/28 14:06
 * Email: Crcker@163.com
 */


class UserPresenter : BasePresenter<UserContract.View>(), UserContract.Presenter {

    private val model by lazy {
        UserModel()
    }

    override fun getUserInfo() {
        checkViewAttached()
        mRootView?.showLoading()
        var disposabl = model
            .getUserInfo()
            .subscribe({ it ->
                mRootView!!.apply {
                    hideLoading()
                    if (it.resultCode == ErrorStatus.SUCCESS) {
                        getUserInfoSuccess(it.datas!!)
                    } else {
                        showError(it.message!!)
                    }
                }
            }, {
                mRootView?.hideLoading()
                mRootView?.showError(ExceptionHandle.handleException(it))
            })

        addSubscription(disposabl)
    }

    override fun changeUserInfo() {
    }
}